#region License
// Resource.cs
// 
// Copyright (c) 2012 Xoqal.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Shammateh.Entities
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;

    public partial class Resource : IDataErrorInfo
    {
        /// <summary>
        /// Gets the full name.
        /// </summary>
        /// <value>
        /// The full name.
        /// </value>
        public string FullName 
        { 
            get 
            { 
                return string.Format("{0} {1}", this.FirstName, this.LastName); 
            } 
        }

        /// <summary>
        /// Gets the error.
        /// </summary>
        /// <value>
        /// The error.
        /// </value>
        public string Error
        {
            get { return null; }
        }

        /// <summary>
        /// Gets the <see cref="System.String" /> with the specified [ERROR: invalid expression IndexerParameter.Name.Words.All].
        /// </summary>
        /// <value>
        /// The <see cref="System.String" />.
        /// </value>
        /// <param name="columnName">Name of the column.</param>
        /// <returns></returns>
        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case "FirstName":
                        if (string.IsNullOrWhiteSpace(this.FirstName))
                        {
                            return ValidationMessageHelper.GetRequiredMessage("نام");
                        }

                        break;
                    case "LastName":
                        if (string.IsNullOrWhiteSpace(this.LastName))
                        {
                            return ValidationMessageHelper.GetRequiredMessage("تام خانوادگی");
                        }

                        break;
                    case "Email":
                        if (string.IsNullOrWhiteSpace(this.Email))
                        {
                            return ValidationMessageHelper.GetRequiredMessage("پست الکترونیکی");
                        }

                        string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
                        if (!string.IsNullOrWhiteSpace(this.Email) && !Regex.IsMatch(this.Email, pattern, RegexOptions.IgnoreCase))
                        {
                            return ValidationMessageHelper.GetIncorectFormatMessage("پست الکترونیکی");
                        }

                        break;
                    default:
                        break;
                }

                return null;
            }
        }
    }
}
